import request from "./request";

const http = {
    async get(url, params) {
        const config = {
            method: 'get',
            url: url
        }
        if (params) {
            let token = localStorage.getItem('token')
            if (token) {
                params.state = token;
            }
            config.params = params
        }
        return await request(config)
    },

    async post(url, data) {
        const config = {
            method: 'post',
            url: url,
        }
        if (data) config.data = data
        return await request(config)
    },

    put(url, data) {
        const config = {
            method: 'put',
            url: url
        }
        if (data) config.data = data
        return request(config)
    },

    delete(url, params) {
        const config = {
            method: 'delete',
            url: url
        }
        if (params) {
            config.params = params
        }
        return request(config)
    }
}

export default http
